import trigger from "../../effect/trigger.js";
import { TriggerOpTypes } from "../../utils.js";

/**
 * 拦截 delete 操作
 * @param {*} target 
 * @param {*} key 
 * @returns 
 */
export default function(target,key){

    // 判断是否存在删除的属性
    const hadKey = target.hasOwnProperty(key)

    const result  = Reflect.deleteProperty(target,key)

    // 若有删除的属性，才进行派发更新
    if(hadKey && result){
        trigger(target,TriggerOpTypes.DELETE,key)
    }

    return result
}